package com.utilcode.util;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.StringRes;

import com.efounder.utils.ResStringUtil;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

/**
 * QMUITipDialog提示，效果不错
 * created by yqs on 2019/4/8
 */
public class QMUIToastUtils {
    /**
     * @param context
     * @param tip     提示内容
     * @param type    QM类型
     */

    public static void showQMUIToast(Context context, @StringRes int tip, int type) {
        String tipString = ResStringUtil.getString(tip);
        showQMUIToast(context, tipString, type);
    }

    public static void showQMUIToast(Context context, String tip, int type) {
        if (context != null) {
            Activity activity = (Activity) context;
            if (activity == null || activity.isFinishing()) {
                return;
            }
        }
        QMUITipDialog.Builder builder = new QMUITipDialog.Builder(context)
                .setTipWord(tip)
                .setIconType(type);
        final QMUITipDialog qmuiTipDialog = builder.create();
        qmuiTipDialog.show();
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                if (qmuiTipDialog != null && qmuiTipDialog.isShowing()) {
                    qmuiTipDialog.dismiss();
                }
            }
        }, 1000);
    }

}
